package br.ita.comp.ces22.quiz.web.action;

import br.ita.comp.ces22.quiz.core.dao.DAO;
import br.ita.comp.ces22.quiz.core.dao.DAOFactory;
import br.ita.comp.ces22.quiz.core.dao.QuizDAO;
import br.ita.comp.ces22.quiz.core.dao.UserDAO;
import br.ita.comp.ces22.quiz.core.exception.InvalidAccessTypeException;
import br.ita.comp.ces22.quiz.domain.Question;

public class ActionDaoManager {
	private static UserDAO userDao = null;
	private static QuizDAO quizDao = null;
	private static DAO<Question> questionDao = null;

	public ActionDaoManager() {
		if (questionDao == null)
			questionDao = DAOFactory.getDAOFactory().getQuestionsDAO();
		
		if (quizDao == null)
			quizDao = DAOFactory.getDAOFactory().getQuizDAO();
		
		if (userDao == null){
			try {
				userDao = DAOFactory.getDAOFactory().getUserDAO();
			} catch (InvalidAccessTypeException ex) {
				ex.printStackTrace();
			}   
		}
	}

	public static DAO<Question> getQuestionDao() {
		return questionDao;
	}

	public static QuizDAO getQuizDao() {
		return quizDao;
	}

	public static UserDAO getUserDao() {
		return userDao;
	}
}
